<?php
/**
 * 用户
 */
namespace App\Http\Controllers;

use App\Service\UserService;
use App\Validation\UserValidation;
use App\Validation\LoginValidation;
use App\Validation\CashValidation;

class UserController extends BaseController
{

	//用户信息
    public function detailAction()
    {
		$this->getUser();
		$data = UserService::getInfo($this->user->member_id);
		$data->avatar = $data->avatar ? $this->getFullUrl($data->avatar, FALSE, $this->config->imgurl) : $this->config->imgurl . '/uploads/default.png';
		return  $this->echoJson($data);
    }
	
	//用户修改
	public function modifyAction()
	{
		$this->getUser();
		
		$raw = $this->validation(new UserValidation, $this->request->getJsonRawBody());

        $data = UserService::save($raw);
		return $this->echoJson('ok');
	}

	//手机绑定
	public function bindMobileAction()
	{
		$this->getUser();
		$raw = $this->validation(new LoginValidation,$this->request->getJsonRawBody());
		$sms_code = $this->redis->get("SMS_CODE_{$raw->mobile}");
		
		if($raw->code != $sms_code){
			$this->echoJson('sms code is not correct',401);
		}
		
		if($this->redis->sIsMember('EWZJ_USERS', $raw->mobile)){
			$this->echoJson('Binded',401);
		}
		
		$this->queue->put(json_encode([
			"command" => "BIND_MOBILE",
			'member_id' => $this->user->member_id,
			'mobile'=> $raw->mobile
		]));
		
		return $this->echoJson('ok');
	}

	//收益-提现
	public function cashAction(){
		$this->getUser();
		$raw = $this->validation(new CashValidation,$this->request->getJsonRawBody());
		
		return $this->echoJson('ok');
	}
	


}